<?php

$name=$_POST['name'];
$slug=$_POST['slug'];
$classname=$_POST['classname'];

include_once "../../common/sql.php";
$conn=connect();
$sql="select count(*) count from categories where name='$name'";
$arr=query($conn,$sql);

$res=["code"=>0,"msg"=>'插入分类信息错误'];

if($arr[0]['count']>0){
    $res['msg']='输入的信息重复';
}else{
$addsql="insert into categories values(null,'$slug','$name','$classname')";
$bool=mysqli_query($conn,$addsql);

if($bool){
    $res['code']=1;
     $res['msg']='插入成功';
     $res['id']=mysqli_insert_id($conn);
}
}
echo json_encode($res);
?>